package com.itheima.web.service.impl.oms;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.service.oms.IOmsOrderReturnReasonService;
import com.itheima.utils.PageResult;
import com.itheima.vo.oms.OmsOrderReturnReason;
import com.itheima.web.mapper.oms.OmsOrderReturnReasonMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;
import java.util.List;


/**
 * <p>
 * 退货原因表 服务实现类
 * </p>
 *
 * @author 王志斌
 * @since 2022-07-06
 */
@DubboService
public class OmsOrderReturnReasonServiceImpl extends ServiceImpl<OmsOrderReturnReasonMapper, OmsOrderReturnReason> implements IOmsOrderReturnReasonService {
    @Autowired
    private OmsOrderReturnReasonMapper orderReturnReasonMapper;
    //根据id，获取单个退货原因详情信息
    @Override
    public OmsOrderReturnReason select(Long id) {
        return orderReturnReasonMapper.selectById(id);
    }
    //修改退货原因
    @Override
    public Integer updateReturnReason(Long id, OmsOrderReturnReason reason) {
        return orderReturnReasonMapper.updateById(reason);
    }
    //修改退货原因启用状态
    @Override
    public Integer updateStatus(Long id, Integer status) {
        OmsOrderReturnReason orderReturnReason = new OmsOrderReturnReason();
        orderReturnReason.setId(id);
        orderReturnReason.setStatus(status);
        return orderReturnReasonMapper.updateById(orderReturnReason);
    }
    //批量删除退货原因
    @Override
    public Integer delete(List<Long> ids) {
        return orderReturnReasonMapper.deleteBatchIds(ids);
    }
    //添加退货原因
    @Override
    public Integer create(OmsOrderReturnReason reason) {
        reason.setCreateTime(LocalDateTime.now());
        return orderReturnReasonMapper.insert(reason);
    }

    @Override
    public PageResult pagelist(Integer pageNum, Integer pageSize) {
        Page<OmsOrderReturnReason> omsOrderReturnReasonPage = new Page<>(pageNum,pageSize);
        orderReturnReasonMapper.selectPage(omsOrderReturnReasonPage,new LambdaQueryWrapper<>());
        return PageResult.init(omsOrderReturnReasonPage.getTotal(),pageNum.longValue(),pageSize.longValue(),omsOrderReturnReasonPage.getRecords());
    }
//分页查询
/*    @Override
    public ResultData pagelist(Integer pageNum, Integer pageSize) {
        Page<OmsOrderReturnReason> page = new Page(pageNum, pageSize);
        QueryWrapper<OmsOrderReturnReason> qw = new QueryWrapper<>();
        qw.orderByDesc("sort", "create_time");
        Page selectPage = orderReturnReasonMapper.selectPage(page, qw);
        this.page(page,qw);
        return ResultData.ok("1",1) ;
    }*/
}
